# coding=utf-8
# @Time    : 2018/3/27 9:43
# @Author  : Jiangxu
# @File    : 十大算法.py
# @Software: PyCharm
# 冒泡排序
def bubbleSort(arr):
	for i in range(1,len(arr)):
		# print "i= %d"%i
		for j in range(len(arr)-i):
			# print "j= %d"%j
			if arr[j] > arr[j+1]:
				arr[j],arr[j+1]=arr[j+1],arr[j]
		# print arr
	return arr


# 选择排序
def selectionSort(arr):
	for i in range(len(arr)-1):
		minIndex = i
		for j in range(i+1,len(arr)):
			if arr[j]<arr[minIndex]:
				minIndex=j
		if i!=minIndex:
			arr[i],arr[minIndex]=arr[minIndex],arr[i]
	return arr


arr1 = [2,56,23,348,1,342]
print bubbleSort(arr1)
print selectionSort(arr1)


